// 
// SoapTrace.Net - A soap message monitoring utility. 
// 
// Copyright (C) 2004 Matthew Ward
// 
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
// 
// Matthew Ward (mrward@users.sourceforge.net)
// 

using System;

using System.Collections;
using System.Diagnostics;
using System.Globalization;

namespace SoapTrace.Core.Communication
{
	/// <summary>
	/// A type safe collection of <see cref="SoapHeaderField"/> objects.
	/// </summary>
	public class SoapHeaderFieldsCollection : CollectionBase
	{
		/// <summary>
		/// Creates a new instance of the <see cref="SoapHeaderFieldsCollection"/>
		/// class.
		/// </summary>
		public SoapHeaderFieldsCollection( )
		{
		}

		/// <summary>
		/// Gets the <see cref="SoapHeaderField"/> object at the specified
		/// index.
		/// </summary>
		public SoapHeaderField this[ int index ]
		{
			[ DebuggerStepThrough ]
			get
			{
				return ( SoapHeaderField )InnerList[ index ];
			}
		}

		/// <summary>
		/// Adds a <see cref="SoapHeaderField"/> object to the collection.
		/// </summary>
		/// <param name="field">The <see cref="SoapHeaderField"/> object
		/// to add.</param>
		public void Add( SoapHeaderField field )
		{
			InnerList.Add( field );
		}

		/// <summary>
		/// Finds a <see cref="SoapHeaderField"/> object with a 
		/// specified name.
		/// </summary>
		/// <param name="name">The name of the header field to look for.</param>
		/// <returns>A matching <see cref="SoapHeaderField"/> object.</returns>
		public SoapHeaderField Find( string name )
		{
			SoapHeaderField MatchedField = null;

			for( int i = 0; ( MatchedField == null ) && ( i < InnerList.Count ); ++i )
			{
				SoapHeaderField Field = ( SoapHeaderField )InnerList[ i ];

				if( String.Compare( Field.Name, name, true, CultureInfo.InvariantCulture ) == 0 )
				{
					MatchedField = Field;
				}
			}

			return MatchedField;
		}
		
		/// <summary>
		///   Copies the <see cref='SoapHeaderFieldsCollection'/> values to a one-dimensional <see cref='Array'/> instance at the 
		///    specified index.
		/// </summary>
		/// <param name='array'>The one-dimensional <see cref='Array'/> that is the destination of the values copied from <see cref='SoapHeaderFieldsCollection'/>.</param>
		/// <param name='index'>The index in <paramref name='array'/> where copying begins.</param>
		/// <exception cref='ArgumentException'>
		///   <para><paramref name='array'/> is multidimensional.</para>
		///   <para>-or-</para>
		///   <para>The number of elements in the <see cref='SoapHeaderFieldsCollection'/> is greater than
		///         the available space between <paramref name='arrayIndex'/> and the end of
		///         <paramref name='array'/>.</para>
		/// </exception>
		/// <exception cref='ArgumentNullException'><paramref name='array'/> is <see langword='null'/>. </exception>
		/// <exception cref='ArgumentOutOfRangeException'><paramref name='arrayIndex'/> is less than <paramref name='array'/>'s lowbound. </exception>
		/// <seealso cref='Array'/>
		public void CopyTo(SoapHeaderField[] array, int index)
		{
			List.CopyTo(array, index);
		}		
		
		/// <summary>
		///   Removes a specific <see cref='SoapHeaderField'/> from the <see cref='SoapHeaderFieldsCollection'/>.
		/// </summary>
		/// <param name='val'>The <see cref='SoapHeaderField'/> to remove from the <see cref='SoapHeaderFieldsCollection'/>.</param>
		/// <exception cref='ArgumentException'><paramref name='val'/> is not found in the Collection.</exception>
		public void Remove(SoapHeaderField val)
		{
			List.Remove(val);
		}	
		
		/// <summary>
		/// <para>Inserts a <see cref='SoapHeaderField'/> into the <see cref='SoapHeaderFieldsCollection'/> at the specified index.</para>
		/// </summary>
		/// <param name='index'>The zero-based index where <paramref name='val'/> should be inserted.</param>
		/// <param name='val'>The <see cref='SoapHeaderField'/> to insert.</param>
		/// <returns><para>None.</para></returns>
		/// <seealso cref='SoapHeaderFieldsCollection.Add'/>
		public void Insert(int index, SoapHeaderField val)
		{
			List.Insert(index, val);
		}	
		
		/// <summary>
		///    <para>Returns the index of a <see cref='SoapHeaderField'/> in 
		///       the <see cref='SoapHeaderFieldsCollection'/> .</para>
		/// </summary>
		/// <param name='val'>The <see cref='SoapHeaderField'/> to locate.</param>
		/// <returns>
		/// <para>The index of the <see cref='SoapHeaderField'/> of <paramref name='val'/> in the 
		/// <see cref='SoapHeaderFieldsCollection'/>, if found; otherwise, -1.</para>
		/// </returns>
		public int IndexOf(SoapHeaderField val)
		{
			return List.IndexOf(val);
		}	
		
		/// <summary>
		/// <para>Gets a value indicating whether the 
		///    <see cref='SoapHeaderFieldsCollection'/> contains the specified <see cref='SoapHeaderField'/>.</para>
		/// </summary>
		/// <param name='val'>The <see cref='SoapHeaderField'/> to locate.</param>
		/// <returns>
		/// <para><see langword='true'/> if the <see cref='SoapHeaderField'/> is contained in the collection; 
		///   otherwise, <see langword='false'/>.</para>
		/// </returns>
		/// <seealso cref='SoapHeaderFieldsCollection.IndexOf'/>
		public bool Contains(SoapHeaderField val)
		{
			return List.Contains(val);
		}		
	}
}
